package com.qhhc.controller;

import com.qhhc.entity.Car;
import com.qhhc.entity.CarOwner;
import com.qhhc.service.impl.CarOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CarOwnerController {
    @Autowired
    private CarOwnerService carOwnerService;

    @RequestMapping("/insertCarOwner")
    public String insertCarOwner(@RequestBody CarOwner carOwner) {
        System.out.println(carOwner);
        carOwnerService.insertCarOwner(carOwner);
        return "success";
    }

    @RequestMapping("/getAllCarOwners")
    public List<CarOwner> getAllCarOwners() {
        return carOwnerService.selectAll();
    }
    @RequestMapping("/getCarOwner/{id}")
    public CarOwner getCarOwnerById(@PathVariable("id") Long id){
        return carOwnerService.selectById(id);
    }
    @RequestMapping("/updateCarOwner")
    public String updateCarOwner(@RequestBody CarOwner carOwner) {
        carOwnerService.updateCarOwner(carOwner);
        return "success";
    }

    @RequestMapping("/deleteCarOwner/{ownerId}")
    public String deleteCarOwner(@PathVariable Long ownerId) {
        carOwnerService.deleteCarOwner(ownerId);
        return "success";
    }
}
